package com.jindy.module.logisticscost.controller;

import com.jindy.common.annotation.Log;
import com.jindy.common.constant.HttpStatus;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.core.page.TableDataInfo;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.logisticscost.domain.LogisticsCost;
import com.jindy.module.logisticscost.service.LogisticsCostService;
import com.jindy.module.outboundorder.domain.OutboundOrder;
import com.jindy.module.outboundorder.service.IOutboundOrderService;
import com.jindy.module.returnapplyorder.domain.ReturnApply;
import com.jindy.module.returnapplyorder.service.IReturnApplyService;
import com.jindy.module.transfer.domain.SyTransferT;
import com.jindy.module.transfer.service.ISyTransferTService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物流费用Controller
 *
 * @author zhaoxi
 * @date 2022-11-12
 */
@Api(tags = "业务后台 - 物流费用管理 ")
@RestController
@RequestMapping("/module/logisticscost")
@Validated
@Slf4j
public class LogisticsCostController extends BaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(LogisticsCostController.class);
    @Autowired
    private LogisticsCostService logisticsCostService;

    @Autowired
    private IOutboundOrderService iOutboundOrderService;

    @Autowired
    private IReturnApplyService iReturnApplyService;

    @Autowired
    private ISyTransferTService syTransferTService;

    /**
     * 查询物流费用数据列表
     */
    @PreAuthorize("@ss.hasPermi('module:logisticscost:list')")
    @GetMapping("/list")
    public TableDataInfo list(LogisticsCost cost){
        try {
            startPage();
            List<LogisticsCost> list = logisticsCostService.selectLogisticsCostList(cost);
            return getDataTable(list);
        } catch (Exception e) {
            LOGGER.error("查询物流费用数据列表异常",e);
            TableDataInfo rspData = new TableDataInfo();
            rspData.setCode(HttpStatus.ERROR);
            rspData.setMsg("查询物流费用数据列表失败");
            return rspData;
        }
    }

    /**
     * 根据id查询物流费用信息详情
     */
    @PreAuthorize("@ss.hasPermi('module:logisticscost:id')")
    @GetMapping(value = "/{id}")
    public AjaxResult get(@PathVariable("id") String id) {
        return AjaxResult.success(logisticsCostService.selectLogisticsCostById(id));
    }

    /**
     * 新增物流费用数据
     */
    @Log(title = "新增物流费用", businessType = BusinessType.INSERT)
//    @PreAuthorize("@ss.hasPermi('module:logisticscost:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LogisticsCost cost)
    {
        return toAjax(logisticsCostService.insertLogisticsCost(cost));
    }

    /**
     * 修改物流费用数据
     */
    @Log(title = "修改物流费用", businessType = BusinessType.UPDATE)
//    @PreAuthorize("@ss.hasPermi('module:logisticscost:update')")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody LogisticsCost cost) {
        return toAjax(logisticsCostService.updateLogisticsCost(cost));
    }

    /**
     * 删除物流费用
     */
    @Log(title = "删除物流费用", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('module:logisticscost:delete')")
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(logisticsCostService.deleteLogisticsCostById(id));
    }

    /**
     * 批量删除
     */
    @Log(title = "批量删除", businessType = BusinessType.DELETE)
//    @PreAuthorize("@ss.hasPermi('module:logisticscost:deletes')")
    @DeleteMapping("/{ids}")
    public AjaxResult removes(@PathVariable String[] ids)
    {
        return toAjax(logisticsCostService.deleteLogisticsCostByIds(ids));
    }

    /**
     * 查询出库单数据
     */
    @PreAuthorize("@ss.hasPermi('module:logisticscost:getOutBoundlist')")
    @GetMapping("/getOutBoundlist")
    public TableDataInfo getOutBoundlist(){
        List<OutboundOrder> list=iOutboundOrderService.getByOutboundNo(logisticsCostService.GetAllOutboundNo());
        return getDataTable(list);
    }

    /**
     * 查询入库单数据
     */
    @PreAuthorize("@ss.hasPermi('module:logisticscost:getReturnlist')")
    @GetMapping("/getReturnlist")
    public TableDataInfo getReturnlist(){
        List<ReturnApply> list=iReturnApplyService.getByReturnNo(logisticsCostService.GetAllReturnNo());
        return getDataTable(list);
    }

    /**
     * 查询调拨单数据
     */
    @PreAuthorize("@ss.hasPermi('module:logisticscost:getTranslist')")
    @GetMapping("/getTranslist")
    public TableDataInfo getTranslist(){
        List<SyTransferT> list=syTransferTService.getByOrderNo(logisticsCostService.GetAllTransferNo());
        return getDataTable(list);
    }

}
